package com.zzptc.easyshop.servlet;

        import com.zzptc.easyshop.factory.DaoFactoryImp;
        import com.zzptc.easyshop.dao.IDAO;
        import com.zzptc.easyshop.dao.UserDao;
        import com.zzptc.easyshop.vo.Users;

        import javax.servlet.ServletException;
        import javax.servlet.annotation.WebServlet;
        import javax.servlet.http.HttpServlet;
        import javax.servlet.http.HttpServletRequest;
        import javax.servlet.http.HttpServletResponse;
        import java.io.IOException;
        import java.io.PrintWriter;
        import java.sql.SQLException;

@WebServlet(name = "LoginServlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter pw=response.getWriter();
     //   pw.print("login succ");
        //接受用户名和密码
        String username=request.getParameter("userName");
        String password=request.getParameter("password");

        Users user=new Users();
        user.getEu_user_name(username);
        user.setEu_password(password);

        //调用dao中的登陆方法

        IDAO userdao=null;
        try {
            userdao=DaoFactoryImp.getlnstance().createDAO("usrdao");
        } catch (Exception e) {
            e.printStackTrace();
        }
        boolean flag=false;
        flag=((UserDao)userdao).login(user);


        if(flag){
            pw.print("login succ welcome");
        }else{
            pw.print("login error");
        }
    }
}
